package cn.jf.modules.system.service;

import cn.jf.modules.system.entity.SysDataLog;
import cn.jf.modules.system.mapper.SysDataLogMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.apache.dubbo.config.annotation.Service;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

@Service(version = "1.0.0")
public class SysDataLogServiceImpl extends ServiceImpl<SysDataLogMapper,SysDataLog> implements ISysDataLogService {
	@Autowired
	private SysDataLogMapper logMapper;

	/**
	 * 添加数据日志
	 */
	@Override
	public void addDataLog(String tableName, String dataId, String dataContent) {
		String versionNumber = "0";
		String dataVersion = logMapper.queryMaxDataVer(tableName, dataId);
		if(dataVersion != null ) {
			versionNumber = String.valueOf(Integer.parseInt(dataVersion)+1);
		}
		SysDataLog log = new SysDataLog();
		log.setDataTable(tableName);
		log.setDataId(dataId);
		log.setDataContent(dataContent);
		log.setDataVersion(versionNumber);
		this.save(log);
	}

	@Override
	public IPage<SysDataLog> getDataLogList(Page<SysDataLog> page, SysDataLog sysDataLog) {
		return page.setRecords(logMapper.getDataLogList(page,sysDataLog));
	}

	@Override
	public List<SysDataLog> getList(SysDataLog sysDataLog) {
		return logMapper.getList(sysDataLog);
	}
}
